"use strict";
cc._RF.push(module, '23102UPQflFWr231qekGv82', 'interactive');
// scripts/interactive.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buttonTip = void 0;
var button_1 = require("./button");
var common = require("./common");
var resource_1 = require("./resource");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var client = common.Client.get();
var log = console.log;
var room_1 = require("./room");
var buttonTip = /** @class */ (function () {
    function buttonTip(btnsinfo, position) {
        var _this = this;
        if (position === void 0) { position = null; }
        this.buttons = [];
        this.anchor = new cc.Node();
        if (!position)
            position = cc.v2(0, -120);
        this.anchor.setPosition(position);
        this.anchor.active = false;
        cc.find("Canvas").addChild(this.anchor);
        btnsinfo.map(function (btn) {
            var button = cc.instantiate(cc.find("Canvas").getComponent(resource_1.default).button).getComponent(button_1.default);
            button.Init(btn);
            _this.anchor.addChild(button.node);
            _this.buttons.push(button);
        });
        this.centerify();
    }
    buttonTip.prototype.centerify = function () {
        var deltaX = 120;
        var num = this.buttons.length;
        for (var i = 0; i < Math.floor(num / 2); i++) {
            this.buttons[i].node.x = -(deltaX * (Math.floor(num / 2) - i));
            this.buttons[this.buttons.length - 1 - i].node.x = (deltaX * (Math.floor(num / 2) - i));
        }
    };
    buttonTip.prototype.show = function (active) {
        if (active === void 0) { active = true; }
        this.anchor.active = active;
    };
    buttonTip.prototype.destroy = function () {
        this.buttons.map(function (btn) { return btn.destroy(); });
        this.anchor.destroy();
    };
    return buttonTip;
}());
exports.buttonTip = buttonTip;
var interactive = /** @class */ (function (_super) {
    __extends(interactive, _super);
    function interactive() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.clickCnt = 0;
        return _this;
    }
    interactive.prototype.onLoad = function () {
        room_1.roomManager.get();
        common.Client.get();
        common.Client.get().receiveHandler = room_1.roomManager.get().receive;
        common.Client.get().connect("joinPlayer");
    };
    interactive.prototype.start = function () {
        // common.setUid('111111')
        // // var handCard = new handCardManager()
        // // handCard.display(handOut.roomInfo.players['111111'].handCards)
        var _this = this;
        // cc.find("Canvas/test").on(cc.Node.EventType.TOUCH_END,touch=>{
        //     // handCard.playOut()
        //     handOut.event = 'joinPlayer'
        //     roomManager.get().receive(handOut)
        //     roomManager.get().usersInfo['111111'].Avatar.showHat()
        //     // handOut.event = 'handOutCards'
        //     // roomManager.get().receive(handOut) 
        //     // handOut.roomInfo.timeto = common.uid
        //     // handOut.event = 'grabCardRes'
        //     // roomManager.get().receive(handOut) 
        //     if(this.clickCnt==0){
        //         // user.showHat()
        //     }
        //     else if(this.clickCnt==1){
        //     }
        //     this.clickCnt++
        // })
        // setTimeout(() => {
        //     client.doTask("preparePlayer") //test
        // }, 500);
        common.Client.get().gameOverHandler = function (data) {
            cc.find("Canvas/gameOver").active = true;
            cc.find("Canvas/gameOver").zIndex = 99;
            cc.find("Canvas/gameOver/gameResult").getComponent(cc.Label).string = data.gameResult[common.uid] ? "win" : "lose";
            cc.find("Canvas/gameOver/back").on(cc.Node.EventType.TOUCH_END, function (touch) {
                cc.director.loadScene("login");
            });
        };
        this.prepareButton = new buttonTip([
            {
                color: 'blue', text: '准备',
                handler: function () {
                    _this.prepareButton.show(false);
                    client.doTask("preparePlayer");
                }
            },
        ]);
        this.prepareButton.show(true);
        var that = this;
        common.Client.get().handOutCardsHandler = function (data) {
            if (data.roomInfo.timeto == common.uid) {
                that.grapButton.show(true);
                // client.doTask('grabCard',{grabRes:1}) //test
            }
        };
        this.grapButton = new buttonTip([
            {
                color: 'blue', text: '不抢',
                handler: function () {
                    _this.grapButton.show(false);
                    client.doTask('grabCard', { grabRes: 0 });
                }
            },
            {
                color: 'yellow', text: '抢地主',
                handler: function () {
                    _this.grapButton.show(false);
                    client.doTask('grabCard', { grabRes: 1 });
                }
            },
        ]);
        common.Client.get().playOutHandler = function (data) {
            if (data.roomInfo.timeto == common.uid)
                that.outButton.show(true);
        };
        this.outButton = new buttonTip([
            {
                color: 'blue', text: '不出',
                handler: function () {
                    _this.outButton.show(false);
                    client.doTask('playOut', { outStyle: null, outCards: [] });
                }
            },
            {
                color: 'yellow', text: '出牌',
                handler: function () {
                    var param = room_1.roomManager.get().userPlayOut();
                    if (param) {
                        _this.outButton.show(false);
                        client.doTask('playOut', param);
                    }
                }
            },
        ]);
    };
    interactive = __decorate([
        ccclass
    ], interactive);
    return interactive;
}(cc.Component));
exports.default = interactive;

cc._RF.pop();